home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / goodies / qtmultiimage / qtmultiimage.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.2 KB  |  120 lines

  1. //////////
  2. //
  3. //    File:        QTMultiImage.c
  4. //
  5. //    Contains:    Code for displaying multiple images contained in a single image file.
  6. //
  7. //    Written by:    Tim Monroe
  8. //
  9. //    Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <2>         10/30/98    rtm        cleaned up code; verified on both Mac and Windows
  14. //       <1>         09/30/98    rtm        first file
  15. //       
  16. //    This file contains code that illustrates how to determine whether an image file contains 
  17. //    more than one image and how to display any of those images. This is useful for working with
  18. //    FlashPix files (which contain multiple resolutions of an image) and PhotoShop files (which
  19. //    store layers as separate images), among others.
  20. //
  21. //    The key new functions to use are GraphicsImportGetImageCount and GraphicsImportSetImageIndex.
  22. //    The rest of the image-handling is done using graphics importer routines that have previously
  23. //    been available.
  24. //
  25. //    This file defines a single function that prompts the user for an image file, determines
  26. //    how many images are contained in that file, and then displays each such image for a short
  27. //    period of time (2 seconds).
  28. //
  29. //////////
  30.  
  31. #include "QTMultiImage.h"
  32.  
  33. WindowPtr                        gImageWindow = NULL;    // the window we display the image in
  34. GraphicsImportComponent            gImporter = NULL;
  35.  
  36.  
  37. //////////
  38. //
  39. // QTMulti_ShowAllImagesInFile
  40. // Display all the images contained in a file.
  41. //
  42. //////////
  43.  
  44. OSErr QTMulti_ShowAllImagesInFile (void)
  45. {
  46.     SFTypeList                    myTypeList;
  47.     StandardFileReply            myReply;
  48.     Rect                        myRect;
  49.     unsigned long                myCount, myIndex, myIgnore;
  50.     OSErr                        myErr = noErr;
  51.  
  52.     //////////
  53.     //
  54.     // have the user select an image file
  55.     //
  56.     //////////
  57.  
  58.     // kQTFileTypeQuickTimeImage means any image file readable by GetGraphicsImporterForFile
  59.     myTypeList[0] = kQTFileTypeQuickTimeImage;
  60.  
  61.     StandardGetFilePreview(NULL, 1, myTypeList, &myReply);
  62.     if (!myReply.sfGood)
  63.         goto bail;
  64.     
  65.     //////////
  66.     //
  67.     // get a graphics importer for the image file and determine how many images are contained in it
  68.     //
  69.     //////////
  70.  
  71.     myErr = GetGraphicsImporterForFile(&myReply.sfFile, &gImporter);
  72.     if (myErr != noErr)
  73.         goto bail;
  74.     
  75.     myErr = GraphicsImportGetImageCount(gImporter, &myCount);
  76.     if (myErr != noErr)
  77.         goto bail;
  78.     
  79.     //////////
  80.     //
  81.     // loop thru all images the image file, drawing each into a window
  82.     //
  83.     //////////
  84.     
  85.     for (myIndex = 1; myIndex <= myCount; myIndex++) {
  86.     
  87.         // set the image index we want to display
  88.         myErr = GraphicsImportSetImageIndex(gImporter, myIndex);
  89.         if (myErr != noErr)
  90.             goto bail;
  91.         
  92.         // determine the natural size of the image
  93.         myErr = GraphicsImportGetNaturalBounds(gImporter, &myRect);
  94.         if (myErr != noErr)
  95.             goto bail;
  96.             
  97.         MacOffsetRect(&myRect, 50, 50);
  98.         
  99.         // create a window to display the image in
  100.         gImageWindow = NewCWindow(NULL, &myRect, myReply.sfFile.name, true, movableDBoxProc, (WindowPtr)-1L, true, 0);
  101.         if (gImageWindow == NULL)
  102.             goto bail;
  103.         
  104.         // set the current port and draw
  105.         GraphicsImportSetGWorld(gImporter, (CGrafPtr)gImageWindow, NULL);        
  106.         GraphicsImportDraw(gImporter);
  107.         
  108.         Delay(kImageDisplayTime, &myIgnore);
  109.         DisposeWindow(gImageWindow);
  110.     }
  111.         
  112. bail:
  113.     if (myErr != noErr)
  114.         if (gImporter != NULL)
  115.             CloseComponent(gImporter);
  116.         
  117.     return(myErr);
  118. }
  119.  
  120.